package com.suian.config;

import com.suian.intercept.MyRestTemplateIntercept;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.BufferingClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

import java.util.Collections;

@Configuration
public class MyConfig {

    @Bean
    //负载均衡Ribbon
    @LoadBalanced
    public RestTemplate restTemplate() {
        RestTemplate restTemplate = new RestTemplate();
//        //添加自定义拦截器
//        RestTemplate restTemplate = new RestTemplate(
//                new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory())
//        );
//        restTemplate.getInterceptors().add(new MyRestTemplateIntercept());
        return restTemplate;
    }
}
